<?php
class Tip extends AppModel {

	var $name = 'Tip';
	var $validate = array(
		'body' => array(
			VALID_NOT_EMPTY
		),
		/*'ip' => array(
			'rule'=>'ip',
			'required' => false
		),*/
		'name' => array(
			VALID_NOT_EMPTY,
			array(
				'rule'=> array('maxLength', 100) 
			)
		),
		'email' => array(
			VALID_NOT_EMPTY,
			array(
				'rule'=> 'email'
			)
		),
		'url' => array(
			'rule'=>array('url', true),
			'allowEmpty' => true
			
		)
	);
	/*
	'allowEmpty' => true
	'message' => __('This field can not be left empty', true)
	var $validate = array(
	        'login' => array(
	            'alphaNumeric' => array(
	                'rule' => 'alphaNumeric',
	                'required' => true,
	                'message' => 'Alphabets and numbers only'
	                ),
	            'between' => array(
	                'rule' => array('between', 5, 15),
	                'message' => 'Between 5 to 15 characters'
	            )
	        ),
	        'password' => array(
	            'rule' => array('minLength', '8'),
	            'message' => 'Mimimum 8 characters long'
	        ),
	        'email' => 'email',
	        'born' => array(
	            'rule' => 'date',
	            'message' => 'Enter a valid date',
	            'allowEmpty' => true
	        )
	    );
	*/
	function afterFind($results, $primary=false) {
	
	if($primary == true) {
		
		//Set::insert($results, 'Tip.0.hest', array('name' => 'files'));
		
		foreach($results as $item => $value) {
			if(isset($results[$item]['Tip']['ip']) and $results[$item]['Tip']['ip'] == $_SERVER['REMOTE_ADDR'] ) {
				$results[$item]['Tip']['can_edit'] = 1;
			} else {
				$results[$item]['Tip']['can_edit'] = 0;
			}
			
		}
		//debug($results);
		//debug($results); 
	  }

	  return $results;
	}

}
?>